﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace rambla.raws.rats
{
    public class outputProfiles
    {
        internal ratsConnection conn;

        public outputProfiles(ratsConnection conn)
        {
            this.conn = conn;
        }

        public Ouput[] items
        {
            get
            {
                return conn.getObjects<Ouput>("/output/");
            }
        }

        public void deleteItem(Ouput item){
            conn.deleteObject("/output/" + item.id + "/");
        }

        public void createItem(Ouput item)
        {
            conn.postObject<Ouput>("/output", item);
        }

        public void updateItem(Ouput item)
        {
            conn.postObject<Ouput>("/output/" + item.id + "/", item);
        }

        public Ouput getItem(string id)
        {
            return conn.getObject<Ouput>("/output/" + id + "/");
        }

        public Ouput getItemByName(string name)
        {
            Ouput ret = null;
            foreach (Ouput item in this.items)
            {
                if (item.name == name)
                {
                    ret = item;
                }
            }
            return ret;
        }
    }

    [XmlRoot(Namespace = "http://rambla.be/raws/ns-metadata/1.0", ElementName = "params")]
    public class Ouput
    {
        ///<summary>
        ///unique (numerical) identifier for the output profile, given by the RATS server when creating it
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string id;

        ///<summary>
        /// a unique name for the output profile, given by the client in the request
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string name;

        ///<summary>
        ///  a description of the output profile
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string description;

        ///<summary>
        /// identifies the kind of export operation (current choices are 'ftp' and 'rass')
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string method;

        ///<summary>
        /// base URI to which the job's filename or target location must be added when determining the export location (if applicable)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string base_uri;

        ///<summary>
        /// base URI to which the job's filename or target location needs to be added when determining the final http location, at which the file will be available after export (if applicable).
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string public_uri;

        ///<summary>
        /// the name of the Rambla CDN to export to (if applicable)
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string cdn;

        ///<summary>
        /// maximum size allowed for source files (in Mb) 
        ///</summary>
        [XmlElement(IsNullable = true)]
        public string max_size;
    }
}
